
var currency = '-';
var exchange = 1.0;
var exchange_item = 1.0;
var grid;

$(function() {
	var columns = [{
	    id: "#",
	    name: "",
	    width: 40,
	    behavior: "selectAndMove",
	    unselectable: true,
	    resizable: false,
	    cssClass: "cell-reorder"
	}, {
	    id: "name",
	    name: "DESCRIPTION OF GOODS",
	    field: "name",
	    width: 150,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text,
	    validator: requiredFieldValidator
	}, {
	    id: "mold",
	    name: "PROJ.NO.",
	    field: "mold_x",
	    width: 150,
	    cssClass: "cell-title",
	    editor: MoldCellEditor
	}, {
	    id: "package",
	    name: "PACKAGE",
	    field: "package",
	    width: 80,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text,
	    validator: requiredFieldValidator
	}, {
	    id: "amount",
	    name: "Quantity",
	    field: "amount",
	    width: 60,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text,
	    validator: requiredFieldValidator
	}, {
	    id: "price",
	    name: "Unit Price",
	    field: "price",
	    width: 80,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text,
	    validator: requiredFieldValidator
	}, {
	    id: "w1",
	    name: "GROSS WEIGHT",
	    field: "w1",
	    width: 80,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text,
	    validator: requiredFieldValidator
	}, {
	    id: "w2",
	    name: "NET WEIGHT",
	    field: "w2",
	    width: 80,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text,
	    validator: requiredFieldValidator
	}, {
	    id: "len",
	    name: "Length",
	    field: "len",
	    width: 60,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text,
	    validator: requiredFieldValidator
	}, {
	    id: "ww",
	    name: "Width",
	    field: "ww",
	    width: 60,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text,
	    validator: requiredFieldValidator
	}, {
	    id: "hh",
	    name: "Height",
	    field: "hh",
	    width: 60,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text,
	    validator: requiredFieldValidator
	}, {
	    id: "content",
	    name: "备注",
	    field: "content",
	    width: 160,
	    cssClass: "cell-title",
	    editor: Slick.Editors.Text
	}, {
	    id: "ok",
	    name: "",
	    field: "ok",
	    width: 40,
	    cssClass: "cell-effort-driven",	    
	    cannotTriggerInsert: true,
	    formatter: Slick.Formatters.YesNo,
	    editor: Slick.Editors.Checkbox
	}];

	var options = {
			editable: true,
		    enableAddRow: true,
		    enableCellNavigation: true,
		    asyncEditorLoading: false,
		    rowHeight: 30
		};
		
	grid = new Slick.Grid($("#myGrid"), data, columns, options);
	
	grid.onAddNewRow.subscribe(function (e, args) {
	// grid.onAddNewRow = function addItem(newItem,columnDef) {
		var item = {name:"aa", amount:"0.0", price: "0.0", ok: true};
        
        $.extend(item, args.item);
        data.push(item);
        // grid.removeRows([data.length - 1]);
        grid.invalidateRows([data.length - 1]);
        grid.updateRowCount();
        grid.render();
        
        total();
    });
    
	grid.onCellChange.subscribe(function(e, args) {
    // grid.onCellChange = function(currentRow, currentCell, item) {
		item = args.item;
		currentCell = args.cell;
		currentRow = args.row;
		
    	// grid.removeRows([currentRow]);
    	grid.updateRowCount();
    	grid.render();
    	
    	total();
    });
});	
